package com.monkey.algorithm.chapter1.accumulator

import edu.princeton.cs.algs4.StdDraw

/**
 * 作者：Monkey
 * 日期：2018/1/24
 */
class VisualAccumulator(val trials: Int, val max: Double) : Accumulator() {
    init {
        StdDraw.setXscale(0.0, trials.toDouble())
        StdDraw.setYscale(0.0, max)
        StdDraw.setPenRadius(.005)
    }

    override fun addDataValue(value: Double) {
        super.addDataValue(value)

        // 绘制随机点
        StdDraw.setPenColor(StdDraw.DARK_GRAY)
        val x = this.count.toDouble()
        StdDraw.point(x, value)
        // 绘制平均值点
        StdDraw.setPenColor(StdDraw.RED)
        StdDraw.point(x, this.mean())
    }
}